<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
/*.easyui-text-2{*/
	/*width:80%; height: 25px;border-radius:5px;border:thin solid #ddd;*/
	/*border-color:#a4e9c1;*/
/*}*/
/*.easyui-select{*/
	/*width:250px; height: 25px;border-radius:5px;border:thin solid #ddd;*/
	/*border-color:#a4e9c1;*/
/*}*/
/*.easyui-text-2area{*/
	/*width:80%;*/
	/*min-height: 50px;border-radius:5px;border:thin solid #ddd;*/
	/*border-color:#a4e9c1;*/
/*}*/
/*.easyui-text-2:focus{*/
	/*outline: none;*/
/*}*/
</style>
<script type="text/javascript">
$(function () {
    $('.task_clear').click(function () {
        $(this).prev().val('');
        $(this).prev().prev().val('');
    })
})

function saveTaskNodeInfo() {
    var data=$('#workflowconfig').serialize();
   $.ajax({
       url:'${ctxPath}/process/saveTaskNodeInfo?procDefId=${procDefId}',
       data:data,
       dataType:'json',
       type:'post',
       success:function (result) {
           if(result.success){
               showMsg(result.msg)
           }
       }
   })
}

function chooseUser(multiSelect,taskDefKey,obj) {
	var userids= $('[name=' + taskDefKey + '_id]').val();
    var url="${ctxPath}/user/toSelectUser?userids="+userids;
    var title='选人';
    var width=250;
    if(multiSelect){
        url="${ctxPath}/user/toMultiSelectUser?userids="+userids;
        title='选候选人';
        width=500;
    }
    var dialog= $('<div>').dialog({
        title:title,
        href:url,
        width : width,
        height : 500,
        onClose : function() {
            $(this).dialog('destroy');
        },
        buttons:[{
            text:'确定',
            handler:function () {
                if (!multiSelect) {
                    var treeObj = $.fn.zTree.getZTreeObj("singleUserTree"); //获取全部节点数据
                    var nodes = treeObj.getCheckedNodes(true);
                    var id = nodes[0].id;
                    var name = nodes[0].text;
                    id = id.replace('USER', '');//用户id
                    $('[name=' + taskDefKey + '_id]').val(id);
                    $('[name=' + taskDefKey + '_name]').val(name);
                } else {
                    var treeObj = $.fn.zTree.getZTreeObj("multiUserTree"); //获取全部节点数据
                    var nodes = treeObj.getCheckedNodes(true);
                    var ids = [], names = [];
                    if (nodes.length > 0) {
                        for (var i = 0; i < nodes.length; i++) {
                            var id = nodes[i].id;
                            if (id.indexOf('USER') > -1) {
                                id = id.replace('USER', '');//用户id
                                ids.push(id);
                                names.push(nodes[i].text);
                            }

                        }
                        
                        $('[name=' + taskDefKey + '_id]').val(ids);
                        $('[name=' + taskDefKey + '_name]').val(names);
                    }
                }
            	dialog.dialog('close');
            }
        },{
            text:'取消',
            handler:function () {
            	dialog.dialog('close');
            }
        }]
    });
}
function chooseGroup(taskDefKey,obj) {
	var title="选择候选组";
	var url="${ctxPath}/jsp/role/roleSelect.jsp";
	var dialog= $('<div>').dialog({
        title:title,
        href:url,
        width : 500,
        height : 500,
        onClose : function() {
            $(this).dialog('destroy');
        },
        buttons:[{
            text:'确定',
            handler:function () {
            	 var rows = roleSelectDataGrid.datagrid('getSelections');
            	 var ids=[];
            	 var names=[];
            	 if(rows.length>0){
            		 for(var i=0;i<rows.length;i++){
            			 ids.push(rows[i].id);
            			 names.push(rows[i].name);
            		 }
            	 }
            	 $('[name=' + taskDefKey + '_id]').val(ids.join(","));
                 $('[name=' + taskDefKey + '_name]').val(names.join(","));
                 dialog.dialog('close');
            }
        }]
	})
}

function selectCondition(obj,taskDefKey){
	 var modal=$('[name='+taskDefKey+'_selectModel]').val(); 
	if(modal=='POSITION'){
		selectPosition(false,taskDefKey+'_conditionId',taskDefKey+'_conditionName');
	}
}
</script>
<div class="easyui-layout" data-options="fit:true,border:false" >
    <div data-options="region:'center',border:false" style="overflow-x:hidden;overflow-y: auto;padding: 3px;" >
       <form id="workflowconfig">
       		<table class="grid">
       		<c:forEach var="l" items="${userTasks}">
       			<tr style="background:#3c8dbc;color:#fff">
       				<td><b>任务名称</b></td>
       				<td colspan="3">
       				<b>${l.taskName}</b>
       				</td>
       			</tr>
       			<tr>
       				<td><b>任务性质</b></td>
       				<td colspan="3">
       					<select name="${l.taskDefKey}_taskCategory" class="easyui-text-2">
       						<option value="0" <c:if test="${l.taskCategory=='0'}">selected</c:if>>单任务</option>
       						<option value="1" <c:if test="${l.taskCategory=='1'}">selected</c:if>>并行任务</option>
       						<option value="2" <c:if test="${l.taskCategory=='2'}">selected</c:if>>多实例</option>
       					</select>
       				</td>
       			</tr>
       			<tr>
       				<td><b>类型</b></td>
       				<td>
       				<input type="radio" name="${l.taskDefKey}_taskType" value="assignee"  onclick="chooseUser(false,'${l.taskDefKey}',this)" <c:if test="${l.taskType=='assignee'}">checked</c:if>/>人员
       				</td>
       				<td>
       					<input type="radio" name="${l.taskDefKey}_taskType" value="candidateUser"  onclick="chooseUser(true,'${l.taskDefKey}',this)"  <c:if test="${l.taskType=='candidateUser'}">checked</c:if>/>候选人
       				</td>
       				<td>
       					<input type="radio" name="${l.taskDefKey}_taskType" value="candidateGroup"  onclick="chooseGroup('${l.taskDefKey}',this)"  <c:if test="${l.taskType=='candidateGroup'}">checked</c:if>/>候选组
       				</td>
       			</tr>
       			<tr>
       				<td><b>设置类型配置</b></td>
       				<td colspan="3">
       				<input type="hidden" name="${l.taskDefKey}_id" value="${l.candidate_ids}"/>
       				<input type="text" class="easyui-text-2" name="${l.taskDefKey}_name" value="${l.candidate_name}" readonly="readonly"/>
       				<a href="javascipt:;" class="task_clear">清除</a>
       				</td>
       			</tr>
       			<tr>
       				<td><b>选择条件</b></td>
       				<td colspan="3">
       					<select name="${l.taskDefKey}_selectModel" class="easyui-select">
       						<option value="">请选择</option>
       						<option value="PREV_SUPERIOR" <c:if test="${l.selectModel eq 'PREV_SUPERIOR'}">selected</c:if>>直接接上级</option>
       						<option value="POSITION" <c:if test="${l.selectModel eq 'POSITION'}">selected</c:if>>指定职位</option>
       					</select>
       					<input type="hidden" name="${l.taskDefKey}_conditionId" value="${l.conditionId}" id="${l.taskDefKey}_conditionId"/>
       					<input id="${l.taskDefKey}_conditionName" type="text" name="${l.taskDefKey}_conditionName" class="easyui-text-2" style="width:200px;" value="${l.conditionName}" readonly="readonly"/>
       					<a href="javascript:void(0)" class="easyui-linkbutton" onclick="selectCondition(this,'${l.taskDefKey}')">选择</a>
       				</td>
       			</tr>
       		</c:forEach>
       		</table>
       </form>
    </div>
</div>